<#include '/admin/sonheader.html' >
<#assign dateformat= "com.enation.framework.directive.DateformateDirective"?new()>	
<style>
  .layui-input{
    width: 80%;
  }
  
  .admin-main{
  	margin-top: 10px;
  }
  
</style>
<div class="admin-main">
    <!--表单区域  -->
	<form id="addgroupbyForm" class="layui-form layui-form-pane" action="">
  		<div class="layui-form-item">
    		<label class="layui-form-label">活动名称：</label>
    		<div class="layui-input-block">
      			<input type="text"  name="act_name" maxlength="30" lay-verify="act_name"  autocomplete="off" class="layui-input" />
    		</div>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">开始时间：</label>
    		<div class="layui-input-inline" >
      			<input class="layui-input" placeholder="开始时间" name="act_start_time" lay-verify="required" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" style="width:100%;height:38px;" />
    		</div>
    		开始时间不能早于：<@dateformat time='${groupbuyActStartTime}' pattern='yyyy-MM-dd HH:mm:ss'/>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">结束时间：</label>
    		<div class="layui-input-inline" >
      			<input class="layui-input" placeholder="结束时间"  name="act_end_time" lay-verify="required" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" style="width:100%;height:38px;" />
    		</div>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">报名截止时间：</label>
    		<div class="layui-input-inline" >
      			<input class="layui-input" placeholder="报名截止时间"  name="act_join_end_time" lay-verify="required" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" style="width:100%;height:38px;" />
    		</div>
  		</div>
  		<div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;z-index:1000; position: fixed;left: 1px;width: 96%;height: 30px; background:rgba(230,230,230,0.8)"> 
	  			<a class="layui-layer-btn0" type="submit" style="margin: 0px 0px 0px 100px;" lay-submit="" lay-filter="savegroupby">保存</a>
  			</div>
  	</form>
</div>
<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name);

layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form()
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;
    
    form.verify({
    	act_name: function(value){
        	if($.trim(value)==""){
          		return '请输入活动名称';
        	}
      	}
    });
   
    //监听提交
    form.on('submit(savegroupby)', function(data){
    	
    	if($("input[name='act_end_time']").val()<$("input[name='act_start_time']").val()){
			$.Loading.error("结束时间不能小于开始时间");
			return false;
		}
    	
    	var now=new Date(parseInt(${groupbuyActStartTime}) * 1000);
    	var datetime = formatDate(now);
    	
    	if($("input[name='act_start_time']").val() <= datetime){
    		$.Loading.error("开始时间已存在团购活动");
    		return false;
    	}
    	
    	var options = {
    			url: ctx+"/shop/admin/group-buy-act/save-add.do",
    			type: "post",
    			dataType: "json",
    			success:function(result){
    				if(result.result==1){
    					$.Loading.success("添加成功");
    					parent.layer.close(index);
    					parent.table.ajax.reload();
    				}
    				if (data.result == 0) {
    					$.Loading.error(data.message);
    				}
    			},
    			error : function(e) {
    				parent.$.Loading.error("出现错误 ，请重试");
    				$.Loading.error(result.message);
    			}
    	};
   		$("#addgroupbyForm").ajaxSubmit(options);
       return false;
    });
});

function formatDate(now) { 
    var year=now.getFullYear(); 
    var month=now.getMonth()+1; 
    var date=now.getDate(); 
    var hour=now.getHours(); 
    var minute=now.getMinutes(); 
    var second=now.getSeconds(); 
   
    if(month<10){
    	month = '0'+month;
    }
    if(date<10){
    	date = '0'+date;
    }
    if(hour<10){
    	hour = '0'+hour;
    }
    if(minute<10){
    	minute = '0'+minute;
    }
    if(second<10){
    	second = '0'+second;
    }
    return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
} 


</script>